﻿using HCDV;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.SessionState;

namespace hcrainMvc
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class WebApiApplication : System.Web.HttpApplication
    {
        //        .你开始不停的刷新的时候压根就没用去用session，所以服务器认为这个会话来源不同的用户。

        //2.当你使用了session的时候，服务器会向客户端发送一个包含sessionid的cookie，（button按钮点击事件里，使用了session.）会发现sessionID不变。

        //或者

        // 只要在Global.ascx中加入:



        protected  void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started

        }

        protected  void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.

        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            BaseConfig.Dbtype = ConfigurationSettings.AppSettings["dbtypehc"];
            if (BaseConfig.Dbtype == "mysql")
            {

                BaseConfig.ConnectionString = ConfigurationSettings.AppSettings["ConnectionString2"];
            }
            else
            { BaseConfig.ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"]; }
            ////初始化日志类
            //log4net.Config.XmlConfigurator.Configure();
            //_log = log4net.LogManager.GetLogger(typeof(Global));

        }
        public override void Init()
        {
            PostAuthenticateRequest += (s, e) => HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
            base.Init();
        }
    }
}